package org.jeecg.modules.app.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.jeecg.common.model.EnumDictOption;
import org.jeecg.common.util.MessageUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.app.entity.AppClient;
import org.jeecg.modules.app.entity.AppUpgrade;
import org.jeecg.modules.app.enums.AppPlatformTypeEnums;
import org.jeecg.modules.app.enums.AppTypeEnums;
import org.jeecg.modules.app.mapper.AppClientMapper;
import org.jeecg.modules.app.mapper.AppUpgradeMapper;
import org.jeecg.modules.app.service.IAppClientService;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 应用管理
 * @Author: sean
 * @Date:   2024-09-30
 * @Version: V1.0
 */
@RequiredArgsConstructor
@Service
public class AppClientServiceImpl extends ServiceImpl<AppClientMapper, AppClient> implements IAppClientService {

//    private final CacheManager cacheManager;
//
//    private final AppUpgradeMapper appUpgradeMapper;

    @Override
    public IPage<AppClient> selectJoinPage(Page page, Wrapper wrapper) {
        IPage<AppClient> pageList = baseMapper.selectJoinPage(page, wrapper);
        if(ObjectUtil.isNotEmpty(pageList) && ObjectUtil.isNotEmpty(pageList.getRecords())){
            pageList.getRecords().forEach(item->{
                AppTypeEnums appTypeEnums = AppTypeEnums.getEnumByValue(item.getAppType());
                if(oConvertUtils.isNotEmpty(appTypeEnums)){
                    item.setAppTypeTxt(MessageUtils.message(appTypeEnums.getRemark()));
                }
                if(oConvertUtils.isNotEmpty(item.getPlatformType())){
                    AppPlatformTypeEnums platformTypeEnums = AppPlatformTypeEnums.getEnumByValue(item.getPlatformType());
                    if(oConvertUtils.isNotEmpty(platformTypeEnums)){
                        item.setPlatformTypeTxt(MessageUtils.message(platformTypeEnums.getRemark()));
                    }
                }
            });
        }
        return pageList;
    }

    @Override
    public List<EnumDictOption> selectOption(AppClient appClient) {
        return baseMapper.selectOption(appClient);
    }

}
